@page "/launch"
@using Unity.ClusterDisplay.MissionControl.MissionControl
@using Unity.ClusterDisplay.MissionControl.EngineeringUI.Components

@{
    var isRunning = MissionControlStatus.State != State.Idle;
    var hasChanges = LaunchConfigurationService.WorkValue.Parameters.Any() ||
        LaunchConfigurationService.WorkValue.LaunchComplexes.Any(c => c.Parameters.Any() || c.LaunchPads.Any(p => p.Parameters.Any()));
    var applyAndSaveEnabled = !isRunning || !hasChanges;
}

<PageTitle>Configuration</PageTitle>
<RadzenStack Orientation="Orientation.Horizontal" JustifyContent="JustifyContent.SpaceBetween" AlignItems="AlignItems.Center" class="page-title-row">
    <RadzenText Text="Configuration" TextStyle="TextStyle.H4" />
    <RadzenStack Orientation="Orientation.Horizontal">
        <RadzenButton Text="Reset to default" Icon="refresh" Click=@ResetToDefault
                      ButtonStyle="ButtonStyle.Light" Disabled=@(!hasChanges) />
        @if (MissionsService.Collection.Any())
        {
            <RadzenSplitButton Click=OnSaveClick Text=@("Save Snapshot")
                           ButtonStyle="ButtonStyle.Info" Disabled=@(!applyAndSaveEnabled)>
                <RadzenSplitButtonItem Text="Overwrite snapshot" />
            </RadzenSplitButton>
        }
        else
        {
            <RadzenButton Click=@(_ => SaveAs()) Text=@("Save Snapshot")
                           ButtonStyle="ButtonStyle.Info" Disabled=@(!applyAndSaveEnabled) />
        }
    </RadzenStack>
</RadzenStack>

<RadzenStack>
    <RadzenLabel Text="Asset" />
    <RadzenDropDownDataGrid AllowClear="true" Style="width: 100%" @ref="m_AssetsDropDown"
                            @bind-Value=@LaunchConfigurationService.WorkValue.AssetId
                            Change="@(args => OnSelectedAssetChanged())"
                            TValue="Guid" ValueProperty="Id" TextProperty="Name"
                            Data=@AssetsService.Collection.Values
                            FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
                            AllowFilteringByAllStringColumns="true"
                            Disabled=@(MissionControlStatus.State != State.Idle)>
        <Columns>
            <RadzenDropDownDataGridColumn Property="Name" Title="Name" />
            <RadzenDropDownDataGridColumn Property="Description" Title="Description" />
        </Columns>
    </RadzenDropDownDataGrid>

</RadzenStack>

<RadzenText Text="Launch Complexes Configuration" Class="data-grid-header height-56 rz-border-base-300" TextStyle="TextStyle.DisplayH6" />
<RadzenDataGrid @ref="m_ComplexesGrid" Data=@Complexes.Collection.Values
                SelectionMode="DataGridSelectionMode.Single">
    <Columns>
        <RadzenDataGridColumn TItem="LaunchComplex" Title="Name" Property="Name" />
        <RadzenDataGridColumn TItem="LaunchComplex" Title="Active Launchpads">
            <Template Context="complex">
                @GetActiveLaunchPads(complex.Id)
            </Template>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn TItem="LaunchComplex" Width="70px">
            <Template Context="complex">
                <RadzenButton Icon="settings" Click=@(() => ConfigureLaunchComplex(complex)) Class="m-1 data-grid-icon" ButtonStyle="ButtonStyle.Light" />
            </Template>
        </RadzenDataGridColumn>
    </Columns>
</RadzenDataGrid>

<RadzenText Text="Global Parameters" Class="data-grid-header height-56 rz-border-base-300" TextStyle="TextStyle.DisplayH6" />
<LaunchParameters Parameters="@LaunchParameters" Values="@LaunchParametersValue" OnValuesUpdated="LaunchParametersValueUpdate" />
